// pages/index/component/nearCar/nearCar.js
import {nlist} from '../../../api/shop';
import {list} from '../../../api/shopCategory'
import {recommendTagList} from '../../../api/recommend';
const app=getApp()
import util from '../../../utils/util'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
			type: Object,
		  }
  },

  lifetimes:{
    attached(){
      // this.loadShopCategory()
      // this.loadRecommendList()
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    shopCategoryId:'',
    shopCategorys:[],
    tabCur: 0, //默认选中
    shops:[],
    pageNum:1,
    tabs: []
  },



  methods: {
    //按标签加载商铺
    loadRecommendList(tagIds){
      let _this = this
			recommendTagList({
        tagIds:tagIds,
        lng:app.globalData.lng,
        lat:app.globalData.lat,
			}).then(res=>{
				console.info("推荐列表信息---",res.data)
				res.data.data.forEach(item=>{
          if(item.hasOwnProperty("shopVo")){
            let shopInfo =  item.shopVo
            shopInfo.logo = util.thumbnail(item.shopVo.logo,190,190)
            shopInfo.distance=util.rateConverter(item.shopVo.distance*1000)
            // item.score=item.score.toFixed(1)
            shopInfo.score= '5.0'
            shopInfo.images=[]
            for(var i=0;i<item.score;i++){
              shopInfo.images.push('https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/ic_list_star_red%402x.png')
            }
            // for(var k=item.images.length;k<5;k++){
            //   item.images.push('https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/canyin/canyin-pingfen-gray.png')
            // }
            this.data.shops.push(shopInfo)
          }
				  })
				  this.setData({
					shops:this.data.shops
				  })
			})
		},
     /**
   * 组件的方法列表
   */
  onReachBottom: function () {
    this.data.pageNum+=1
    // this.loadShop()

   },
   downRefresh(){
    this.data.shops=[]
    this.data.pageNum=1
    this.data.shopCategoryId=""
    // this.loadShop()
   },
    loadShop(){
      nlist({
        scopeType: 2,
        pageNum:this.data.pageNum,
        shopCategoryId:this.data.shopCategoryId,
        lng:app.globalData.lng,
        lat:app.globalData.lat,
        }).then(res=>{
          res.data.data.forEach(item=>{
            item.logo = util.thumbnail(item.logo,190,190)
            item.distance=util.rateConverter(item.distance)
            // item.score=item.score.toFixed(1)
            item.score= '5.0'
            item.images=[]
            for(var i=0;i<item.score;i++){
              item.images.push('https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/ic_list_star_red%402x.png')
            }
            // for(var k=item.images.length;k<5;k++){
            //   item.images.push('https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/canyin/canyin-pingfen-gray.png')
            // }
            this.data.shops.push(item)
          })
          this.setData({
            shops:this.data.shops
          })
          wx.stopPullDownRefresh()
      })
    },

    loadShopCategory(){
      list({
        scopeType:2
      }).then(res=>{
        res.data.unshift({
            name:'全部',
            id:'',
        })
          res.data.forEach((item,index)=>{
            item.index=index
          })
          this.loadShop()
          this.setData({
            shopCategorys: res.data
          })
      })
    },
    tabSelect(e) {
      this.data.shops=[]
      this.data.pageNum=1
      this.setData({
        shopCategoryId:e.currentTarget.dataset.id,
        tabCur: e.currentTarget.dataset.index,
        scrollLeft: (e.currentTarget.dataset.index - 2) * 200
      })
      this.loadShop()
    }

  }
})
